package com.polaris.live.popup

import android.content.Context
import androidx.recyclerview.widget.GridLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.blankj.utilcode.util.StringUtils
import com.lxj.xpopup.core.BottomPopupView
import com.polaris.live.R
import com.polaris.live.adapter.diamond.DiamondPopupAdapter
import com.polaris.live.common.ext.setOnSingleClickListener
import com.polaris.live.databinding.PopupDiamondSelectBinding
import com.polaris.live.resp.bean.DiamondSelectBean
import com.polaris.live.translation.R.string

/**
 * DiamondPopup
 *
 * @author Created by 半仙 on 2023/10/28/028 13:53
 */
class DiamondPopup(
    context: Context,
    private val position: Int? = null,
    private val selectPosition: (type: Int?) -> Unit,
) :
    BottomPopupView(context) {

    private lateinit var mBinding: PopupDiamondSelectBinding

    private val mAdapter: DiamondPopupAdapter by lazy {
        DiamondPopupAdapter()
    }

    override fun getImplLayoutId(): Int {
        return R.layout.popup_diamond_select
    }

    override fun onCreate() {
        super.onCreate()
        mBinding = PopupDiamondSelectBinding.bind(popupImplView)
        mBinding.recycler.apply {
            adapter = mAdapter
            layoutManager = GridLayoutManager(context, 2, RecyclerView.VERTICAL, false)
        }
        mAdapter.setList(list)
        mAdapter.setOnItemClickListener { _, view, position ->
            selectPosition.invoke(list[position].type)
            dismiss()
        }
        mBinding.tvBack.setOnSingleClickListener {
            dismiss()
        }
        list.forEachIndexed { index, it ->
            if (it.type == position) {
                mAdapter.setSelect(index)
            }
        }
    }

    companion object {

        val list = listOf(
            DiamondSelectBean(
                R.drawable.diamond_po_all,
                StringUtils.getString(string.diamond_all),
                null
            ),
            DiamondSelectBean(
                R.drawable.diamond_po_gift,
                StringUtils.getString(string.diamond_gifts),
                1
            ),
//            DiamondSelectBean(
//                R.drawable.diamond_po_call,
//                StringUtils.getString(string.diamond_video_call),
//                3
//            ),
//            DiamondSelectBean(
//                R.drawable.diamond_po_game,
//                StringUtils.getString(string.diamond_game),
//                4
//            ),
            DiamondSelectBean(
                R.drawable.diamond_po_recharge,
                StringUtils.getString(string.diamond_top_up),
                2
            ),
            DiamondSelectBean(
                R.drawable.ic_diamond_type,
                StringUtils.getString(string.platform_reward),
                5
            ),
            DiamondSelectBean(
                R.drawable.ic_diamond_casual_games,
                StringUtils.getString(string.casual_games),
                6
            ),
            DiamondSelectBean(
                R.drawable.ic_diamond_lucky_bag,
                StringUtils.getString(string.coin_lucky_bag),
                7
            ),
            DiamondSelectBean(
                R.drawable.ic_diamond_dress_up,
                StringUtils.getString(string.dress_up),
                8
            ),
            DiamondSelectBean(
                R.drawable.ic_diamond_room,
                StringUtils.getString(string.room_string),
                9
            )
        )
    }
}